#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>

</style>
#end

#define js()
<script type="text/javascript">
    layui.use(['table', 'layer'], function () {
        var table = layui.table
            , $ = layui.jquery
            , button;
        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , id: 'dateTable'
            , even: true //开启隔行背景
            , size: 'sm' //小尺寸的表格
            , height: 'full-150'    //容器高度
            , contentType: 'application/json; charset=UTF-8'
            , cols: [[                  //标题栏
                {type: 'numbers', fixed: true, unresize: 'true'}
                , {field: 'name', title: '项目名称', minWidth: 200, sort: true}
                , {field: 'createTime', title: '创建时间', minWidth: 150, sort: true}
                , {
                    field: 'status',
                    title: '状态',
                    minWidth: 100,
                    sort: true,
                    templet: '#statusTpl(io.jboot.admin.service.entity.status.system.ApplyInviteStatus::me(), "status")'
                }
                , {field: 'reply', title: '回复', minWidth: 150}
                , {title: '操作', minWidth: 200, align: 'center', toolbar: '#barOption'}
            ]]
            , url: '#(ctxPath)/app/project/reviewProjectTable'
            , method: 'get'
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true
            , limits: [30, 60, 90, 150, 300]
            , limit: 30 //默认采用30
            , loading: true
            , where: {
                applyOrInvite: true, flag: 1
            }
            , done: function (res, curr, count) {
            }
        });


        table.on('tool(dateTable)', function (obj) {
            var data = obj.data;
            console.log(obj);
            if (obj.event === 'pass') {
                layer.confirm('确定通过吗？(此操作不可逆！)', function (index) {
                    $.post("#(ctxPath)/app/project/saveInviteReview", {
                        id: data.id,
                        invite: 2,
                        type: 0
                    }, function () {
                        layer.msg("审查完成！");
                        setTimeout(function () {
                        }, 1000);
                        table.reload('dateTable', {
                            url: '#(ctxPath)/app/project/reviewProjectTable?applyOrInvite=' + true + '&flag=1'
                        });
                    });
                });
            } else if (obj.event === 'noPass') {
                layer.open({
                    type: 1
                    , title: false //不显示标题栏
                    , closeBtn: false
                    , area: '300px;'
                    , shade: 0.8
                    , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                    , btn: ['不通过', '我再想想']
                    , btnAlign: 'c'
                    , moveType: 1 //拖拽模式，0或者1
                    , content: '' +
                    '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">' +
                    '<label class="layui-form-label">不通过缘由</label>' +
                    '<textarea placeholder="请输入内容" class="layui-textarea" name="desc">' +
                    '</textarea>' +
                    '</div>'
                    , success: function (layero) {
                        var btn = layero.find('.layui-layer-btn');
                        btn.find('.layui-layer-btn0').on('click', function () {
                            var textarea = layero.find('textarea')[0];
                            $.post("#(ctxPath)/app/project/saveInviteReview", {
                                id: data.id,
                                reply: textarea.value,
                                invite: 1,
                                type: 0
                            }, function () {
                                layer.msg("审查完成！");
                                setTimeout(function () {
                                }, 1000);
                                table.reload('dateTable', {
                                    url: '#(ctxPath)/app/project/reviewProjectTable?applyOrInvite=' + true + '&flag=1'
                                });
                            });
                        });
                    }
                });
            } else if (obj.event === 'view') {
                pop_show_full('预审报告', '#(ctxPath)/app/ass_review/findPageAndShow?projectId=' + data.projectID + '&roleType=3'
                    , function () {
                        window.location.reload();
                    });
            }
        });


        $('#invite').on('click', function () {
            table.render({
                elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
                , id: 'dateTable'
                , even: true //开启隔行背景
                , size: 'sm' //小尺寸的表格
                , height: 'full-150'    //容器高度
                , contentType: 'application/json; charset=UTF-8'
                , cols: [[                  //标题栏
                    {type: 'numbers', fixed: true, unresize: 'true'}
                    , {field: 'name', title: '项目名称', minWidth: 200, sort: true}
                    , {field: 'createTime', title: '创建时间', minWidth: 150, sort: true}
                    , {
                        field: 'status',
                        title: '状态',
                        minWidth: 100,
                        sort: true,
                        templet: '#statusTpl(io.jboot.admin.service.entity.status.system.ApplyInviteStatus::me(), "status")'
                    }
                    , {field: 'reply', title: '回复', minWidth: 150}
                    , {title: '操作', minWidth: 200, align: 'center', toolbar: '#barOption'}
                ]]
                , url: '#(ctxPath)/app/project/reviewProjectTable'
                , method: 'get'
                , request: {
                    pageName: 'pageNumber' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                , page: true
                , limits: [30, 60, 90, 150, 300]
                , limit: 30 //默认采用30
                , loading: true
                , where: {
                    applyOrInvite: true, flag: 1
                }
                , done: function (res, curr, count) {
                }
            });
        });

        $('#reviewed').on('click', function () {
            table.render({
                elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
                , id: 'dateTable'
                , even: true //开启隔行背景
                , size: 'sm' //小尺寸的表格
                , height: 'full-150'    //容器高度
                , contentType: 'application/json; charset=UTF-8'
                , cols: [[                  //标题栏
                    {type: 'numbers', fixed: true, unresize: 'true'}
                    , {field: 'name', title: '项目名称', minWidth: 200, sort: true}
                    , {field: 'createTime', title: '创建时间', minWidth: 150, sort: true}
                    , {
                        field: 'status',
                        title: '状态',
                        minWidth: 100,
                        sort: true,
                        templet: '#statusTpl(io.jboot.admin.service.entity.status.system.ApplyInviteStatus::me(), "status")'
                    }
                    , {field: 'reply', title: '回复', minWidth: 150}
                    , {title: '操作', minWidth: 200, align: 'center', toolbar: '#barOption-reviewed'}
                ]]
                , url: '#(ctxPath)/app/project/reviewProjectTable'
                , method: 'get'
                , request: {
                    pageName: 'pageNumber' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                , page: true
                , limits: [30, 60, 90, 150, 300]
                , limit: 30 //默认采用30
                , loading: true
                , where: {
                    applyOrInvite: true, flag: 2
                }
                , done: function (res, curr, count) {
                }
            });
        });

    });
</script>
#end

#define content()

<div class="reloadChoose">
    <button class="layui-btn" id="invite">查看正在审查的项目</button>
    <button class="layui-btn" id="reviewed">查看审查完成的项目</button>
</div>

<div class="layui-fluid">
    <div class="layui-row">
        <table id="dateTable" lay-filter="dateTable"></table>
    </div>
</div>

<script type="text/html" id="barOption">

    #[[
    {{#  if(d.status == '2'){ }}
    ]]#
    <a class="layui-btn layui-btn-xs" lay-event="view">查看预审报告</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="pass">通过</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="noPass">不通过</a>
    #[[
    {{#  } }}
    ]]#
</script>

<script type="text/html" id="barOption-reviewed">
    #[[
    {{#   if(d.status == '3'){ }}
    ]]#
    <a class="layui-btn layui-btn-warm layui-btn-xs layui-disabled" disabled="disabled">已通过</a>
    #[[
    {{# } else if(d.status == '4'){ }}
    ]]#
    <a class="layui-btn layui-btn-warm layui-btn-xs layui-disabled" disabled="disabled">拒绝通过</a>
    #[[
    {{#  } }}
    ]]#
</script>
#end

